package com.xiaoyun.controller;

import com.alibaba.fastjson.JSON;
import com.xiaoyun.service.IMerchantsService;
import com.xiaoyun.vo.CreateMerchantsRequest;
import com.xiaoyun.vo.PassTemplate;
import com.xiaoyun.vo.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/merchants")
@Api
public class MerchantsCtl {
    private final IMerchantsService merchantsService;

    @Autowired
    public MerchantsCtl(IMerchantsService merchantsService) {
        this.merchantsService = merchantsService;
    }

    @PostMapping("/create")
    @ApiOperation("创建商户服务")
    public Response createMerchants(@RequestBody CreateMerchantsRequest request) {
        log.info("CreateMerchants:{}", JSON.toJSONString(request));

        return merchantsService.createMerchants(request);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id构建商户信息")
    public Response buildMerchantsInfo(@PathVariable Integer id) {
        log.info("buildMerchantsInfo:{}", id);
        return merchantsService.buildMerchantsInfoById(id);
    }

    @PostMapping("/drop")
    @ApiOperation("投放优惠券")
    public Response dropPassTemplate(@RequestBody PassTemplate passTemplate) {
        log.info("DropPassTemplate:{}", passTemplate);
        return merchantsService.dropPassTemplate(passTemplate);
    }
}
